# Tanım: ileri düzey exploit kullanarak geliştirme ve test etme çatı uygulaması
# URL: http://www.metasploit.com
# Paketçi: milisarge yakar
# Gerekler: ruby libpcap postgresql ruby-bundler sqlite libxslt clang
# Grup: güvenlik

isim=metasploit
surum=4.17.23
devir=1
kaynak=(https://github.com/rapid7/metasploit-framework/archive/$surum.tar.gz::$isim-$surum.tar.gz)

derle() {
	cd "${isim}-framework-$surum"
	bundle config build.nokogiri --use-system-libraries
	sed 's|git ls-files|find -type f|' -i metasploit-framework.gemspec
	export CC=clang
	export CXX=clang++
	bundle install -j"$(nproc)" --no-cache --deployment
	find vendor/bundle/ruby -exec chmod o+r '{}' \;

	install -d "${PKG}/opt/${isim}" "${PKG}/usr/bin"
	find . -maxdepth 1 -mindepth 1 -not -path './.git*' -exec cp -r '{}' "${PKG}/opt/${isim}" \;

	for f in "${PKG}"/opt/${isim}/msf*; do
	local _msffile="${PKG}/usr/bin/`basename "${f}"`"
	echo -e "#!/bin/sh\nBUNDLE_GEMFILE=/opt/${isim}/Gemfile bundle exec ruby /opt/${isim}/`basename "${f}"` \"\$@\"" > "${_msffile}"
	chmod 755 "${_msffile}"
	done

	(cd "${PKG}/opt/${isim}"
	for f in tools/*/*.rb; do
	  install -Dm 755 "${f}" ".${f}"
	  echo -e "#!/bin/sh\nBUNDLE_GEMFILE=/opt/${isim}/Gemfile bundle exec ruby /opt/${isim}/."${f}" \"\$@\"" > "${f}"
	  chmod 755 "${f}"
	done
	)

	install -Dm 644 external/zsh/_* -t "${PKG}/usr/share/zsh/site-functions"
	install -d "${PKG}/usr/share/doc"
	mv "${PKG}/opt/${isim}/documentation" "${PKG}/usr/share/doc/${isim}"
	rm "${PKG}/usr/bin/msfupdate"
	
  	# desktop
	mkdir -p "$PKG/usr/share/applications/"
	cat > $PKG/usr/share/applications/$isim.desktop << BASLA
[Desktop Entry]
Name=metasploit
Exec=sh -c "msfconsole;${SHELL:-bash}"
Terminal=true
Icon=msfconsole
Type=Application
Categories=Network;X-Komutan;
Version=1.0
BASLA
}
